<html>
<head>
<meta charset="UTF-8"/>
<title>es</title>
<script src="js/jquery-3.1.1.js"></script>
</head>
<noscript><h2 style="color: #e80b0a;">Sorry，浏览器不支持WebSocket</h2></noscript>
<div>
<p id="data"></p>
</div>
<script type="text/javascript">
    $(function() {
        const eventSource = new EventSource("/event-stream");
        const dataDiv = $('#data');
        eventSource.onmessage = function(event) {
            console.log('Received message:'+event.data);
            dataDiv.append(event.data);
        };
        eventSource.onerror = function(error) {
            console.error('EventSource failed:'+error);
            dataDiv.append(error);
            eventSource.close();
        };
      /*  eventSource.addEventListener('open', function() {
            console.log("connection opened");
        });

        eventSource.addEventListener('my-event', function(event) {
            console.log("event received: " + JSON.stringify(event));
            dataDiv.append(event.data);
        });

        eventSource.addEventListener('error', function() {
            console.log("connection error");
        });

        eventSource.addEventListener('end', function() {
            console.log("connection ended");
        });*/
    });
</script>
</body>
</html>
